<?php
function controller_sanggar($config) {
    $db = new db($config);
    //deskripsi
	$result = $db->query( "SELECT * FROM `deskripsi` WHERE page = 'sanggar'" );
	$desc = str_replace("\n", "<br />", $result[0]['deskripsi']);
	$param['deskripsi'] = $desc;
	//twitter
	$result = $db->query( "SELECT twitter FROM `footer` WHERE 1" );
	$param['twitter'] = $result[0]['twitter'];
	//sanggar
	$result = $db->query("SELECT * FROM `sanggar` WHERE 1");
	$param['sanggar'] = array();
	foreach ($result as $sanggar){
		//sanggar
		$id = $sanggar['idSanggar'];
		$param['sanggar'][$id] = $sanggar;
		//slider
		$uploaddir = $config['image_path'].'sanggar'.DIRECTORY_SEPARATOR.'komu'.DIRECTORY_SEPARATOR;
		$gambar = array();
		$regex = $uploaddir.$id."-*";
		$limitedext = array("jpg","jpeg","png","bmp");
		//slide
		foreach (glob($regex) as $files) {
			$getFile = explode(DIRECTORY_SEPARATOR,$files);
			$file = $getFile[count($getFile)-1];
			$getExt = explode('.',$file);
			$file_ext = $getExt[count($getExt)-1];
			if (in_array($file_ext,$limitedext)) {
				$img = $config['image_url'].'sanggar/komu/'.$file;
				array_push($gambar, $img);
			}
		}
		$param['sanggar'][$id]['slide'] = $gambar;
		//pp
		$uploaddir = $config['image_path'].'sanggar'.DIRECTORY_SEPARATOR.'pp'.DIRECTORY_SEPARATOR;
		$pp = "";
		$regex = $uploaddir.$id."*";
		$limitedext = array("jpg","jpeg","png","bmp");
		//slide
		foreach (glob($regex) as $files) {
			$getFile = explode(DIRECTORY_SEPARATOR,$files);
			$file = $getFile[count($getFile)-1];
			$getExt = explode('.',$file);
			$file_ext = $getExt[count($getExt)-1];
			if (in_array($file_ext,$limitedext)) {
				$img = $config['image_url'].'sanggar/pp/'.$file;
				$pp = $img;
			}
		}
		$param['sanggar'][$id]['pp'] = $pp;
	}
	//
	//var_dump($param['sanggar']);
	view_sanggar($config, $param);
}
